/*     */ package com.zimbra.cs.service.account;
/*     */ 
/*     */ import com.zimbra.common.localconfig.KnownKey;
/*     */ import com.zimbra.common.localconfig.LC;
/*     */ import com.zimbra.common.mailbox.ContactConstants;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.AccountConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.util.StringUtil;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.EntrySearchFilter;
/*     */ import com.zimbra.cs.account.GalContact;
/*     */ import com.zimbra.cs.account.ldap.LdapEntrySearchFilter.LdapQueryVisitor;
/*     */ import com.zimbra.cs.gal.GalExtraSearchFilter;
/*     */ import com.zimbra.cs.gal.GalExtraSearchFilter.FilteredGalSearchResultCallback;
/*     */ import com.zimbra.cs.gal.GalExtraSearchFilter.GalExtraQueryCallback;
/*     */ import com.zimbra.cs.gal.GalSearchControl;
/*     */ import com.zimbra.cs.gal.GalSearchParams;
/*     */ import com.zimbra.cs.gal.GalSearchQueryCallback;
/*     */ import com.zimbra.cs.gal.GalSearchResultCallback;
/*     */ import com.zimbra.cs.mailbox.Contact;
/*     */ import com.zimbra.cs.service.util.ItemIdFormatter;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import com.zimbra.soap.type.GalSearchType;
/*     */ import java.util.Arrays;
/*     */ import java.util.HashSet;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class SearchCalendarResources
/*     */   extends GalDocumentHandler
/*     */ {
/*     */   public boolean needsAuth(Map<String, Object> context)
/*     */   {
/*  51 */     return true;
/*     */   }
/*     */   
/*     */   public Element handle(Element request, Map<String, Object> context) throws ServiceException
/*     */   {
/*  56 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*  57 */     Account account = getRequestedAccount(getZimbraSoapContext(context));
/*     */     
/*  59 */     if (!canAccessAccount(zsc, account)) {
/*  60 */       throw ServiceException.PERM_DENIED("can not access account");
/*     */     }
/*  62 */     return searchGal(zsc, account, request);
/*     */   }
/*     */   
/*     */   private static Element searchGal(ZimbraSoapContext zsc, Account account, Element request)
/*     */     throws ServiceException
/*     */   {
/*  68 */     Element name = request.getOptionalElement("name");
/*     */     
/*  70 */     EntrySearchFilter filter = GalExtraSearchFilter.parseSearchFilter(request);
/*     */     
/*  72 */     GalSearchParams params = new GalSearchParams(account, zsc);
/*  73 */     params.setQuery(name == null ? null : name.getText());
/*     */     
/*  75 */     if (filter != null) {
/*  76 */       params.setExtraQueryCallback(new CalendarResourceExtraQueryCallback(filter));
/*     */     }
/*     */     
/*  79 */     params.setType(GalSearchType.resource);
/*  80 */     params.setRequest(request);
/*  81 */     params.setResponseName(AccountConstants.SEARCH_CALENDAR_RESOURCES_RESPONSE);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*  87 */     if (request.getAttribute("limit", null) == null) {
/*  88 */       request.addAttribute("limit", 100L);
/*     */     }
/*     */     
/*     */ 
/*  92 */     params.setLimit(LC.calendar_resource_ldap_search_maxsize.intValue());
/*     */     
/*  94 */     String attrsStr = request.getAttribute("attrs", null);
/*  95 */     String[] attrs = attrsStr == null ? null : attrsStr.split(",");
/*  96 */     Set<String> attrsSet = attrs == null ? null : new HashSet(Arrays.asList(attrs));
/*     */     
/*  98 */     params.setResultCallback(new CalendarResourceGalSearchResultCallback(params, filter, attrsSet, null));
/*     */     
/* 100 */     GalSearchControl gal = new GalSearchControl(params);
/* 101 */     gal.search();
/* 102 */     return params.getResultCallback().getResponse();
/*     */   }
/*     */   
/*     */   private static class CalendarResourceExtraQueryCallback extends GalExtraSearchFilter.GalExtraQueryCallback implements GalSearchQueryCallback
/*     */   {
/*     */     public CalendarResourceExtraQueryCallback(EntrySearchFilter filter) {
/* 108 */       super();
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */     public String getZimbraLdapSearchQuery()
/*     */     {
/* 121 */       LdapEntrySearchFilter.LdapQueryVisitor visitor = new LdapEntrySearchFilter.LdapQueryVisitor();
/* 122 */       this.filter.traverse(visitor);
/* 123 */       String query = visitor.getFilter();
/* 124 */       return StringUtil.isNullOrEmpty(query) ? null : query;
/*     */     }
/*     */   }
/*     */   
/*     */   private static class CalendarResourceGalSearchResultCallback extends GalExtraSearchFilter.FilteredGalSearchResultCallback
/*     */   {
/*     */     private CalendarResourceGalSearchResultCallback(GalSearchParams params, EntrySearchFilter filter, Set<String> attrs) {
/* 131 */       super(filter, attrs);
/*     */     }
/*     */     
/*     */     public Element handleContact(Contact contact) throws ServiceException
/*     */     {
/* 136 */       ToXML.encodeCalendarResource(getResponse(), this.mFormatter.formatItemId(contact), contact.get(ContactConstants.A_email), contact.getAllFields(), neededAttrs(), null);
/*     */       
/*     */ 
/* 139 */       return null;
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */     public void handleContact(GalContact galContact)
/*     */       throws ServiceException
/*     */     {
/* 148 */       if ((galContact.isZimbraGal()) || (matched(galContact))) {
/* 149 */         ToXML.encodeCalendarResource(getResponse(), galContact.getId(), galContact.getSingleAttr(ContactConstants.A_email), galContact.getAttrs(), neededAttrs(), null);
/*     */       }
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/account/SearchCalendarResources.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */